Skip to content

feat: Screen Config Postgres Client APIs and Admin Logic - #3231

Open
robbie-sundstrom wants to merge 10 commits into
mainfrom
rs/scm/api-initial
Open

feat: Screen Config Postgres Client APIs and Admin Logic#3231
robbie-sundstrom wants to merge 10 commits into
mainfrom
rs/scm/api-initial

Conversation

@robbie-sundstrom

Copy link
Copy Markdown
Contributor

Asana task: Define Screen Config shared APIs

  • Adds APIs for fetching all configs and editing a list of configs that will be called by Screenplay. These are protected behind API authorization]
    • Note that I’ve tested calling the API to fetch all configs from Screenplay locally and it’s in working order
  • Modifies Screens Admin. This was initially a separate task, and is split into a separate commit with this work. Including this work allowed me to better understand how I should design use of the feature flag, and what could be shared between the two.
    • The existing index Screens Admin endpoint now calls a different function that handles the feature flag logic
    • There is a new screen_configs endpoint that handles modifying/deleting screen configs in JSON or Postgres based on the feature flag

Frontend Changes

  • Fetching all configs
    • The structure of the JSON we pass could be simplified, but after playing around with it, I think this would be easiest after the migration. Keeping the same nested format for now
  • Making updates to configs
    • Since this currently passes back the full JSON to make changes, the FE now passes different data based on the feature flag it receives from the BE. This is handled by the new function commitScreenConfigChanges.
    • editor.tsx calls this directly
    • inspector.tsx now calls this within the AdminForm component.

@robbie-sundstrom
robbie-sundstrom requested a review from a team as a code owner August 11, 2026 15:32
@robbie-sundstrom robbie-sundstrom changed the title Rs/scm/api initial feat: Screen Config Postgres Client APIs and Admin Logic Aug 11, 2026
Comment thread lib/screens_web/router.ex
Comment thread assets/src/components/admin/admin_form.tsx Outdated
Comment thread lib/screens/screen_configs.ex
Comment thread lib/screens/screen_configs.ex Outdated
Comment thread lib/screens/screen_configs.ex Outdated
end)
end

@doc """

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my own understanding, we have a mix of @doc comments and blocks of comments (e.g.). How do we determine what we want to doc with @doc vs not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do need to be consistent with this 😅 I kind of like the @doc comments because of how they integrate with tools like ElixirLS in VSCode. But I do generally think the @doc comments are moreso for API consumers, which is why we generally don't have them throughout our codebase. I'll move towards consistency here, which I'd like to be @doc comments for this new file at least

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Elixir convention as far as I've seen is @doc for public functions and # blocks for private functions, since private functions are treated as "hidden" anyway and there's no way to access docs attached to them beyond looking at the code. Technically the main purpose of @doc is in generating ExDocs which are made available on Hex for published libraries; in an application codebase, it's mostly useful for editor LS integration. I usually include them if there's something important for callers to know that isn't covered by the function name, argument names, and typespec, which is all also readily accessible via LSP. (This is not just "for API consumers" in the sense of "consumers of some API external to the whole application", but if you take an expansive view of an "API" as "the set of public functions exported by a module", then that is accurate!)

Comment thread lib/screens/screen_configs.ex Outdated
Comment thread lib/screens/screen_configs.ex Outdated
Comment thread lib/screens/screen_configs.ex
Comment thread lib/screens_web/controllers/screen_configs_api_controller.ex Outdated

@rwaskiewicz rwaskiewicz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for making those changes. Two non-blocking comments

onConfirm: (config: any) => Promise<{ success: boolean; error?: string }>;
configRef: RefObject<HTMLTextAreaElement | null>;
onCancel: () => void;
onError: (string) => void;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking nit - it looks like the parameter name (or type, depending how you look at it) here is omitted:

Suggested change
onError: (string) => void;
onError: (errorMsg: string) => void;

But looking at it's usage here, maybe its type is more than that of type string?

} else {
onError(result.error);
}
} catch (error) {
onError(error);

where in the else clause, result.error can be undefined, and if the catch clause, error is of type unknown. Keeping the API boundary between components the same, one potential type-safe solution could be:

      if (result.success === true) {
        onSuccess();
      } else if (result.error) {
        onError(result.error);
      } else {
        onError(`An unknown exception occurred updating the config`);
      }
    } catch (error: unknown) {
      if (error instanceof Error) {
        onError(error.message);
      } else if (error && typeof error === 'object' && 'toString' in error) {
        onError(error.toString())
      } else {
        onError(`An unknown exception occurred....we would need to make this distinct from the other exception where we have no idea what happened`);
      }
    }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right! Parsing these unknown/undefined errors into strings seems like a good solution to me

Comment thread assets/src/util/admin.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants